<%--
  Created by IntelliJ IDEA.
  User: 34662
  Date: 2023/6/23
  Time: 16:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <!-- 引入 layui.css -->
    <link href="https://cdn.staticfile.org/layui/2.7.6/css/layui.css" rel="stylesheet">

    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
</head>
<style>
    body{
        margin-left: 20px;
    }
    .layui-input, .layui-textarea{
        width: 300px;
    }
</style>
<body>
<form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    订单
                    <input type="text" disabled name="quotationNumber" required  lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
                <div class="layui-form-item">
                    <div class="layui-input-inline">
                        款号
<%--                        <input type="text" name="styleNumberId" id="styleNumberId">--%>
                        <input type="text" disabled name="styleNumberId" required  lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                    <div class="layui-form-item">
                        <div class="layui-input-inline">
                            商品
                            <input type="text" disabled name="productDetailId" required  lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
        <div class="layui-form-item">
            <div class="layui-input-inline">
                尺寸
                <input type="text" name="size" disabled   lay-verify="required"required  autocomplete="off" class="layui-input">
            </div>
        </div>
    <div class="layui-form-item">
        <div class="layui-input-group">
            <div class="layui-input-split layui-input-prefix">
                今日已生产数量
            </div>
            <input type="text"  name="producedCount" placeholder="今日已生产数量" class="layui-input">
        </div>
    </div><br>
</form>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
    </div>
</div>
</body>
<script>

    //在写一个ajax，获取款号的id获取商品信息,之后和渲染订单款号一样，选择好之后填入今天生产数量，添加
    //或者简单一点把所有的要添加的颜色、尺码、款号、都改称对应的表如：颜色就加颜色id，款号就直接加款号id
 //    getSize()
 // function getSize() {
 //
 // }
    var params = new URLSearchParams(window.location.search);
    var jsonData  = params.get('data'); // 获取URL参数中的data值
    var data = JSON.parse(decodeURIComponent(jsonData)); // 将JSON字符串解析为对象

    layui.use(['element', 'layer','form'], function () {
        var element = layui.element,
            form = layui.form,
            layer = layui.layer;
         $('[name=quotationNumber]').val(data.quotationNumber);
        $('[name=styleNumberId]').val(data.styleName);
        $('[name=productDetailId]').val(data.productName);
        $('[name=size]').val(data.name);
        //监听提交
        let orderId = data.orderId;
        var orderStyleRelId = data.orderStyleRelId;
        let colorKindSizeMaterialsRelId = data.colorKindSizeMaterialsRelId;
        let productionPlanId = data.productionPlanId;
        form.on('submit(formDemo)', function(){
            let producedCount = $('[name=producedCount]').val();
                if (producedCount == null || producedCount == ''){
                    layer.alert("生产数量不能为空")
                    return false;
                }
                if (isNaN(producedCount)  && producedCount > 0){
                    layer.alert("请填写正确的生产数量")
                    return false;
                }

            let data = {
                orderId:orderId,
                orderStyleRelId:orderStyleRelId,
                colorKindSizeMaterialsRelId:colorKindSizeMaterialsRelId,
                producedCount:producedCount,
                productionPlanId:productionPlanId
            };
            let ino = JSON.stringify(data);
            console.log(ino)
            $.ajax( {
                "url"            :  "sewingManager/addSubmission",
                "type"         :  "post",
                "data"         :  ino,
                "dataType" :  "json",
                "contentType":"application/json;charset=utf-8;",
                "success"  :  function(result) {
                    console.log(result)
                    layer.msg(result.msg);
                    $('[name=producedCount]').val("");
                    parent.layer.close(index);
                    parent.location.reload();
                },
                "error"       :  function() {
                    alert("出错了")
                }
            } )

        });
    });
</script>

</html>
